package com.wc.acwing.二进制.空调II;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/14 23:07
 * @description
 * https://www.acwing.com/problem/content/4892/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 25, M = 15, K = 110;
    static int[][] cow = new int[N][3], ac = new int[N][4];
    static int[] w = new int[K];
    static int n, m;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                cow[i][j] = sc.nextInt();
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < 4; j++) {
                ac[i][j] = sc.nextInt();
            }
        }

        int res = (int)1e8;
        for (int i = 0; i < 1 << m; i++) {
            Arrays.fill(w, 0);
            int cost = 0;
            for (int j = 0; j < m; j++) {
                if ((i >> j & 1) == 1) {
                    int a = ac[j][0], b = ac[j][1], p = ac[j][2], m = ac[j][3];
                    for (int k = a; k <= b; k++) {
                        w[k] += p;
                    }
                    cost += m;
                }
            }
            boolean success = true;
            for (int j = 0; j < n; j++) {
                int s = cow[j][0], t = cow[j][1], c = cow[j][2];
                for (int k = s; k <= t; k++) {
                    if (w[k] < c) {
                        success = false;
                        break;
                    }
                }
                if (!success) break;
            }
            if (success) res = Math.min(res, cost);
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

